import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import {resolve} from "path";
import {viteMockServe} from "vite-plugin-mock";     // mock配置
import Inspect from 'vite-plugin-inspect'       // 解析文件编译过程
import VueSetupExtend from 'vite-plugin-vue-setup-extend' // setup语法糖配置name属性
import AutoImport from 'unplugin-auto-import/vite'  // 自动导入vue的属性
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' // 自动导入naive
import Components from 'unplugin-vue-components/vite'   // 自动导入公共组件
import WindiCSS from 'vite-plugin-windicss'
// https://vitejs.dev/config/

export default ({command})=>{
  console.log(command,"启动命令是什么")
  return {
    plugins: [
      vue(),VueSetupExtend(),Inspect(),WindiCSS(),
      AutoImport({
        imports: ['vue',],
      }),
      Components({resolvers:[NaiveUiResolver(),]}),
      viteMockServe({
        // default
        mockPath: 'mock',
        localEnabled: command === 'serve',
      }),
    ],
    resolve: {
      alias: {
        '@': resolve(__dirname, 'src'),
      },
    },
    server: {
      open: false,
      host: '0.0.0.0',
      port:5000,
      proxy: {
        '/proxy': {
          target: 'http://127.0.0.1:8000/',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/proxy/, '')
        },
      },
    },
  }
}
